/**
 * 
 */
package hu.gbalage.owlforms.xforms.work;

import java.io.File;
import java.net.URI;

import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyChangeException;

import hu.gbalage.owlforms.OWLFormsManager;
import hu.gbalage.owlforms.api.Form;
import hu.gbalage.owlforms.api.data.FormData;
import hu.gbalage.owlforms.xforms.Constants;

/**
 * @author balage
 *
 */
public class Boot {

	static String[] onts = new String[]{//"szocpont.owl","szoctam.owl"
			"lib/swrl.owl",
			"lib/swrla.owl",
			"lib/swrlb.owl",
			"lib/swrlx.owl",
			"lib/abox.owl",
			"lib/tbox.owl",
			"lib/temporal.owl",
			"lib/query.owl",
			"core.owl",
			"person.owl",
			"eltartottak.owl",
			"egyforeesojovedelem.owl",
			"szoctam_hallgato.owl",
			"dontes.owl",
			"szoctam_form.owl"
		};
	
	public static final OWLFormsManager manager = new OWLFormsManager();
	
	static{
		String boot = WorkManager.boot.getPath();
		for(String ont : onts){
			manager.loadOntology(new File(boot+"/"+ont).toURI());
		}
	}
	
	public static void save(FormData data) throws OWLOntologyChangeException{
		OWLOntology o = manager.createWritableOntology(URI.create("http://owlforms.gbalage.hu/usr/"+data.getURI().getFragment()+".owl"), 
				new File(WorkManager.usr.getPath()+"/"+data.getURI().getFragment()+".owl").toURI());
		manager.saveFormData(data, o);
		manager.saveOntology(o);
	}
	
	public static FormData load(Form form, String fragment) throws OWLReasonerException{
		manager.loadOntology(new File(WorkManager.usr.getPath()+"/"+fragment+".owl").toURI());
		return manager.load(form, URI.create(Constants.OWLForms_SAVE_BASE+fragment));
	}
}
